var t = getApp();

Page({
    data: {
        rewardMoneyBtn: !1,
        page: 1
    },
    onLoad: function(t) {},
    toRecord: function(t) {
        var e = t.currentTarget.dataset.id;
        console.log(e), wx.navigateTo({
            url: "/packageE/energy/powerNotes/powerNotes?id=" + e
        });
    },
    Delete: function(e) {
        var a = e.currentTarget.dataset.id, n = t.getNetAddresss("plugin.energy-cabin.frontend.dealer-terminal.del-equipment"), o = this, s = {
            id: a
        };
        t._getNetWork({
            url: n,
            data: s,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (console.log(e), wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                }), o.getdata()) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    swichTabTItem: function(t) {
        console.log(t);
    },
    bindEquipment: function() {
        wx.navigateTo({
            url: "/packageE/energy/bindEquipment/bindEquipment"
        });
    },
    taperwei: function(t) {
        var e = t.currentTarget.dataset.info;
        console.log(e), this.setData({
            rewardMoneyBtn: !0,
            codeimg: e.qr_code_url
        });
    },
    saveImg: function() {
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {}
                });
            }
        });
        var t = this.data.codeimg;
        wx.downloadFile({
            url: t,
            success: function(t) {
                wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        });
                    },
                    fail: function(t) {
                        "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && wx.openSetting({
                            success: function(t) {
                                t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                    icon: "none",
                                    title: "获取权限成功,再次长按保存图片",
                                    duration: 1500
                                }) : wx.showToast({
                                    icon: "none",
                                    title: "获取权限失败,保存图片需要用户授权",
                                    duration: 1500
                                });
                            }
                        });
                    },
                    complete: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    onClose: function(t) {
        this.setData({
            rewardMoneyBtn: !1
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getdata();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getdata: function() {
        var e = t.getNetAddresss("plugin.energy-cabin.frontend.dealer-terminal.get-equipment-list"), a = this, n = {
            page: this.page
        };
        t._getNetWork({
            url: e,
            data: n,
            success: function(t) {
                var e = t.data;
                1 == e.result && (console.log(e), e.data.data.forEach(function(t, e, a) {
                    t.checked = !1, t.info = {};
                }), a.setData({
                    datas: e.data.data,
                    current_page: e.data.current_page,
                    last_page: e.data.last_page,
                    total: e.data.total
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    expand: function(e) {
        var a = e.currentTarget.dataset.info, n = e.currentTarget.dataset.ind;
        if (a.checked) {
            for (var o = 0; o < this.data.datas.length; o++) this.data.datas[n].checked = !a.checked;
            this.setData({
                datas: this.data.datas
            });
        } else {
            wx.showLoading({
                title: "加载中"
            });
            var s = {
                id: a.id
            }, i = t.getNetAddresss("plugin.energy-cabin.frontend.dealer-terminal.get-device-data"), c = this;
            t._getNetWork({
                url: i,
                data: s,
                success: function(t) {
                    wx.hideLoading({
                        success: function(t) {}
                    });
                    var e = t.data;
                    if (1 == e.result) {
                        console.log(e);
                        for (var o = 0; o < c.data.datas.length; o++) c.data.datas[n].info = e.data, c.data.datas[n].checked = !a.checked;
                        c.setData({
                            datas: c.data.datas
                        });
                    }
                },
                fail: function(t) {
                    wx.hideLoading({
                        success: function(t) {}
                    }), console.log(t);
                }
            });
        }
    }
});